//
//  ZYUIConstant.swift
//  ZYUICommon
//
//  Created by Yi Zhou on 2025/1/6.
//

import Foundation
import UIKit

/// keywindow
public let zKeyWindow = UIApplication.shared.keyWindow

/// 屏幕宽
public let zScreenWidth: CGFloat = UIScreen.main.bounds.width

/// 屏幕高
public let zScreenHeight: CGFloat = UIScreen.main.bounds.height

/// 比例：以375 * 667为基准
public let zScaleW: CGFloat = zScreenWidth / 375.0
public let zScaleH: CGFloat = zScreenHeight / 667.0

/// 状态栏高度
public var zStatusBarHeight: CGFloat {
    get {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
            return scene?.statusBarManager?.statusBarFrame.height ?? 0
        } else {
            return UIApplication.shared.statusBarFrame.height
        }
    }
}

/// 导航栏高度
public let zNavBarHeight: CGFloat = 44.0

/// 导航栏+状态栏高度
public var zTopHeight: CGFloat {
    get {
        return zStatusBarHeight + zNavBarHeight
    }
}

/// 安全边距距离 在delegate window 创建之前调用会得到.zero 横竖屏切换该值不会改变
public var zSafeAreaInsets: UIEdgeInsets {
    get {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
            return scene?.windows.first?.safeAreaInsets ?? .zero
        } else {
            return UIApplication.shared.delegate?.window??.safeAreaInsets ?? .zero
        }
    }
}

/// 底部安全距离
public var zSafeBottomMargin: CGFloat {
    get {
        return zSafeAreaInsets.bottom
    }
}
